Skip to content

Implement graceful shutdown with ConsolePlus.BeginCriticalRender - #13

Merged
FRACerqueira merged 3 commits into
mainfrom
develop
Aug 10, 2026
Merged

Implement graceful shutdown with ConsolePlus.BeginCriticalRender#13
FRACerqueira merged 3 commits into
mainfrom
develop

Conversation

@FRACerqueira

Copy link
Copy Markdown
Owner

This pull request introduces a new mechanism to safely handle critical render or cleanup sections in the console application, ensuring these sections are given a short grace period to complete when Ctrl+C is pressed before the process exits. This prevents output from being torn down mid-write while still guaranteeing that Ctrl+C will not hang indefinitely. The release version is also incremented.

Critical render/cleanup section handling:

  • Added the BeginCriticalRender() method to ConsolePlus, allowing code to mark a critical section that should be given a short, bounded grace period to finish when Ctrl+C is pressed. The critical section is exited by disposing the returned IDisposable handle; nesting is supported. [1] [2]
  • Implemented internal synchronization logic using _criticalRenderLock, _criticalRenderIdle, and _criticalRenderCount to track and manage active critical sections.
  • Modified the Ctrl+C handler (Console_CancelKeyPress) to wait up to 300ms (configurable via _criticalRenderGracePeriod) for in-flight critical render sections to complete before forcing the process to exit, ensuring the application cannot hang indefinitely.

Documentation:

  • Added API documentation for the new BeginCriticalRender() method in ConsolePlus.

Versioning:

  • Bumped the package version to 1.0.0-rc2 in ConsolePlus.csproj.

FRACerqueira and others added 3 commits August 10, 2026 11:27
Console_CancelKeyPress cancelled the token and called Environment.Exit
immediately, with no way for in-flight render/cleanup code to finish first.
Add ConsolePlus.BeginCriticalRender(), a disposable scope that makes the
handler wait up to 300ms after cancelling before forcing the process to exit.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Added documentation for ConsolePlus.BeginCriticalRender() in ConsolePlus.md, detailing its purpose, usage, and return value. Updated PromptPlus.csproj to set GeneratePackageOnBuild to true, enabling automatic NuGet package generation during build.
@FRACerqueira
FRACerqueira merged commit 78cea4d into main Aug 10, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant